<?php

namespace App\Http\Controllers\Api\V2;

use App\Http\Controllers\Api\BaseController;
use App\Models\Book;
use App\Models\SellCart;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class SellCartController extends BaseController
{
    public function feedback(Request $request)
    {
        $id = intval($request->get('id'));
        if(empty($id))
        {
            return $this->err(1,200,'','参数错误');
        }

        $cart = SellCart::query()->where('id',$id)->where('user_id',$this->user_id)->first();
        if(empty($cart))
        {
            return $this->err(1,200,'','记录不存在');
        }

        if($cart->is_feedback_recyle)
        {
            return $this->err(1,200,'','已反馈');
        }

        $cart->update(['is_feedback_recyle' => 1]);
        if(!empty($cart->book_id))
        {
            Book::query()->where('id',$cart->book_id)->increment('feedback_recyle_count');
            Book::query()->where('id',$cart->book_id)->update(['feedback_recyle_time' => $this->time]);
        }

        return $this->ok([]);
    }
}
